package sy1_UML.association;
/**
 * 类间关联示例
 * Customer与Product存在一对多关系
 */
import java.util.ArrayList;
import java.util.List;

class Customer {  //顾客类
	private String customer_name; // 顾客名称
	private List<Product> products=new ArrayList<Product>(); // 顾客购买的多种产品

	public Customer(String customer_name) {  //构造方法
		this.customer_name = customer_name;
	}
	
	public String getCustomer_name() {  //getter
		return customer_name;
	}
	
	public List<Product> getProducts() {  //getter
		return products;
	}

	public void showProducts(List<Product> products) {  //普通方法
		for (Product product : products) {
			System.out.println(product.getProduct_name());
		}
	}
	
	/*public void setCustomer_name(String customer_name) {  //setter
		this.customer_name = customer_name;
	}*/
}

class Product {  //产品类
	private String product_name; // 产品名称
	//private Customer customer; // 产品的购买者（单个）

	public String getProduct_name() {
		return product_name;
	}
	
	public Product(String product_name) {  //构造方法
		this.product_name = product_name;
	}

	/*public void setProduct_name(String product_name) {
		this.product_name = product_name;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}*/

	/*public void show_ProductBuyer(Customer customer) {
		System.out.println("产品购买者：" + customer.getCustomer_name());
	}*/
}

public class CustomerAndProduct {   //测试类
	public static void main(String[] args) {
		Product product1 = new Product("牙膏");
		Product product2 = new Product("牙刷");
		Product product3 = new Product("毛巾");
		
		Customer customer = new Customer("张三");
		List<Product> products = customer.getProducts();
		products.add(product1);
		products.add(product2);
		products.add(product3);
		
		System.out.println(customer.getCustomer_name()+"购买的产品如下：");
		customer.showProducts(products);
	}
}
